/***************************************************************************
创建者：华磊
开始时间：               : 2019.12.17
copyright            : (C) 深圳市华友高科有限公司
 ***************************************************************************/
#include "fleetdebugview.h"
#include "ui_fleetdebugview.h"
#include <QTimer>
#include "../CommunicateDelegate/communicatedelegate.h"

FleetDebugView::FleetDebugView(int styleId,CommunicateNormalDelegate *communicateNormalThreadIn, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FleetDebugView)
{
    ui->setupUi(this);

    communicateNormalThread=communicateNormalThreadIn;
    ui->setupUi(this);
    move(0,0);
    initialDisplayStyle(styleId);

    timer=new QTimer;
    connect( timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()) );
}

void FleetDebugView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        this->setGeometry(0,0,600,570);
        ui->tabWidget->setGeometry(10,30,580,530);

        ui->textEdit_socketFleetRequest->setGeometry(10,10,560,480);
        ui->textEdit_modbusFleetRequest->setGeometry(10,10,560,480);
        break;
    default:
        break;
    }
}

FleetDebugView::~FleetDebugView()
{
    delete ui;
}

void FleetDebugView::showView_slot()
{
    show();
    timer->start(500);
}

void FleetDebugView::timeOutSlot()
{
    showFleetInfo();
}

void FleetDebugView::showFleetInfo()
{
    if(false==ui->checkBox_isUpdateFleetInfo->isChecked())
    {
        return ;
    }
    //socket fleet
    FleetCommandDebugInfo tmpReturnInfo;
    communicateNormalThread->getSocketFleetCommandLog(tmpReturnInfo);
    ui->textEdit_socketFleetRequest->clear();
    int tmpSize=tmpReturnInfo.fleetCommandLog.size();
    for(int i=0;i<tmpSize;i++)
    {
        ui->textEdit_socketFleetRequest->append(QString::fromStdString(tmpReturnInfo.fleetCommandLog[i]));
    }
    ui->textEdit_socketFleetRequest->moveCursor(QTextCursor::EndOfLine);

    //modbus fleet
    communicateNormalThread->getModbusFleetCommandLog(tmpReturnInfo);
    ui->textEdit_modbusFleetRequest->clear();
    for(int i=0;i<tmpReturnInfo.fleetCommandLog.size();i++)
    {
        ui->textEdit_modbusFleetRequest->append(QString::fromStdString(tmpReturnInfo.fleetCommandLog[i]));
    }
    ui->textEdit_modbusFleetRequest->moveCursor(QTextCursor::EndOfLine);


    return;
}


//void FleetDebugView::on_pushButton_fleetViewReturn_clicked()
//{
//    hide();
//    timer->stop();
//}


